{include file="public/base" /}
{block name="main"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加管理员</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form method="get" action="javascript:;" class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">账号:</label>
                            <div class="col-sm-10">
                                <input type="text" name="account"  minlength="3" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">密码:</label>
                            <div class="col-sm-10">
                                <input type="password" name="pwd" minlength="6" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">确认密码：</label>
                            <div class="col-sm-10">
                                <input type="password" name="repwd" minlength="6" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">店铺</label>
                            <div class="col-sm-10">
                                <select name="shop" class="form-control">
                                    <option value="">--请选择--</option>
                                    {foreach name="list" id="val"}
                                    <option value="{$val.id}">{$val.name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">权限</label>
                            <div class="col-sm-10">
                                <select name="isadmin" class="form-control">
                                    <option value="0">普通管理员</option>
                                    <option value="1">超级管理员</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="submit" onclick="return edit()">保存内容</button>
                                <!--<button class="btn btn-white" type="submit">取消</button>-->
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="javascript"}
<script src="ADMIN_JS/content.min.js?v=1.0.0"></script>
<script src="ADMIN_JS/plugins/iCheck/icheck.min.js"></script>
<script>
    function edit()
    {
        var account = $("[name='account']").val();
        var pwd = $("[name='pwd']").val();
        var repwd = $("[name='repwd']").val();
        var isadmin = $("[name='isadmin']").val();
        var shop = $("[name='shop']").val();
        if (pwd!=repwd){
            alert('输入的两次密码不一致！');
            return false;
        }
        if (shop==''){
            alert('请选择店铺！');
            return false;
        }
        var loading = layer.msg('正在提交数据，请稍后...', {icon: 16,time:3000});
        $.ajax({
            type:'post',
            url:'{:url("admin/add")}',
            data:{'isadmin':isadmin,'pwd':pwd,'account':account,'shop':shop},
            success:function(data){
                layer.close(loading);
                if(data.code==1){
                    layer.msg(data.msg,{icon:6,time:1500});
                    setTimeout(function(){window.parent.location.reload();},1000);
                }else{
                    layer.msg(data.msg,{icon:5,time:1500});
                }
            }
        })
    }

</script>
{/block}